<?php

class Product extends AppModel {
	
	public $name = 'Product';
	
	public $displayField = 'title';
	
	public $belongsTo = array(
        'Picture' => array (
            'className' => 'Resource',
			'foreignKey' => 'picture_id'
        ),
		'User' => array (
			'className' => 'User',
			'foreignKey' => 'user_id'
		),
		'Category' => array(
			'className' => 'ProductCategory',
			'foreignKey' => 'category_id'
		)
    );
	
	public function __construct() {
		parent::__construct();
		$this->Picture->Behaviors->load('Uploader.Attachment', array(
			'file' => array (
				'nameCallback' => 'getFileName',
				'append' => '-original',
				'prepend' => '',
				'overwrite' => true,
				'stopSave' => true,
				'allowEmpty' => true,
				'dbColumn' => '',
				'uploadDir' => 'pictures/products/',
				'finalPath' => '/pictures/products/',
				'defaultPath' => '/pictures/products/default.png',
				'metaColumns' => array (
					'basename' => 'name',
					'type' => 'type',
					'size' => 'size',
					'width' => 'width',
					'height' => 'height'
				),
				'transforms' => array (
					'thumb' => array (
						'method' => AttachmentBehavior::CROP,
						'append' => '-small',
						'overwrite' => true,
						'self' => false,
						'location' => 'center',
						'width' => 180,
						'height' => 180,
						'defaultPath' => '/pictures/products/default.png',
					),
					'small' => array (
						'method' => AttachmentBehavior::RESIZE,
						'append' => '-thumb',
						'overwrite' => true,
						'self' => false,
						'width' => 120,
						'height' => 120,
						'aspect' => true,
						'defaultPath' => '/pictures/products/default.png',
					)
				)
			)
		));
	}
	
}